//@author A0106044W
package logic;

import java.util.ArrayList;

import storage.Date;
import storage.Task;
import storage.Time;

/**
 * 
 *
 * 	       Sothearith Sreang
 *         All of the Logic part is written by me.
 * 
 */

public class DisplayTaskInfoList {
	
	ArrayList<Task> taskList;
	
	private static final boolean isDisplayTaskIndexMode = true;
	
	private static final boolean COMPLETE_STATUS = true;
	private static final boolean PENDING_STATUS = false;
	
	public DisplayTaskInfoList(ArrayList<Task> taskListP) {
		taskList = taskListP;
	}
	
	public ArrayList<DisplayTaskInfo> getTaskAttributesList(boolean mode) {

		ArrayList<DisplayTaskInfo> allTasksAttr = new ArrayList<DisplayTaskInfo>();

		for (int i = 0; i < taskList.size(); i++) {
			Task task = taskList.get(i);
			
			String description = task.getDescription();
			Date startDate = task.getDateRange()
					.getStartDate();
			Time startTime = task.getTimeRange()
					.getStartTime();
			Date endDate = task.getDateRange()
					.getEndDate();
			Time endTime = task.getTimeRange()
					.getEndTime();
			boolean status = task.getDoneStatus();
			boolean overDue = task.getOverdueStatus();
			
			DisplayTaskInfo displayTaskInfo = null;
			try {
				displayTaskInfo = new DisplayTaskInfo(description, startDate, endDate, startTime, endTime, status, overDue);
			} catch (Exception e) {
				
			}
			
			if(mode == isDisplayTaskIndexMode) {
				int index = Logic.getDisplayTaskList().indexOf(task);
				displayTaskInfo.setIndex(index);
			}
			
			allTasksAttr.add(displayTaskInfo);
			
		}

		return allTasksAttr;
	}
	
	public int getNumberOfPendingTasks() {
		return getNumberOfStatusTasks(PENDING_STATUS);
	}
	
	public int getNumberOfCompleteTasks() {
		return getNumberOfStatusTasks(COMPLETE_STATUS);
	}
	
	// next level abstraction
	
	private int getNumberOfStatusTasks(boolean status) {
		int statusTasksCount = 0;
		
		for(Task task: taskList){
			if(task.getDoneStatus() == status) {
				statusTasksCount++;
			}
		}
		
		return statusTasksCount;
	}

}
	
